<?php

use yii\helpers\Url;
use yii\grid\GridView;
use yii\helpers\Html;
use app\base\helpers\ArrayHelper;
use app\base\enums\StatusEnum;


$this->title = '文章管理';
$this->params['breadcrumbs'][] = $this->title;
?>


<?php $this->beginBlock('content-header'); ?>
<h1>
	<?php echo $this->title?> <a class="btn bg-purple btn-flat btn-xs "
		href="<?= Url::to(['create']) ?>"> <?= Yii::t('hass', '写文章') ?>
	</a>
</h1>
<?php $this->endBlock(); ?>

<div class="box box-solid">
	<div class="box-body no-padding">
        <?php
        echo GridView::widget([
            'layout' => "{items}",
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'filterPosition'=>GridView::FILTER_POS_HEADER,
            "tableOptions"=>['class' => 'table table-hover table-striped no-margin'],
            "columns"=>[
                [
                   'attribute' => 'title',
                    "format"=>"html",
                    'value'=>function($model, $key, $index, $column)
                    {
                         $params = is_array($key) ? $key : ['id' => (string) $key];
                         $params[0] = "update";
                         $value =  ArrayHelper::getValue($model, $column->attribute);
                         return Html::a($value,$params);
                    }
                ],
                'views',
                [
                    'class' => 'app\base\misc\grid\SwitcherColumn',
                    'attribute' => 'status',
                    'filter'=>StatusEnum::listData()
                ],
                [
                    'class' => 'app\base\misc\grid\ActionColumn',
                    'urlCreator'=>function($action, $model, $key, $index,$column)
                    {
                        if($action =="view")
                        {
                            $params = is_array($key) ? $key : ['id' => (string) $key];
                            $params[0] ="/post/view";
                            return \Yii::$app->get("appUrlManager")->createUrl($params);
                        }
                    }
                ]
            ]

        ]);
        ?>
	</div>
	<div class="box-footer">
		<div class="box-tools pull-right">
			<?=yii\widgets\LinkPager::widget(['pagination' => $dataProvider->pagination,'options'=>['class' => 'pagination pagination-sm inline']])?>
		</div>
	</div>
</div>